<template>
  <div>
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :label-col="{ style: { width: '80px' } }">
        <a-form-item name="pyjm" label="" class="w-[300px]">
          <a-input v-model:value="formState.pyjm" placeholder="药品编号/药品名称/助记码/姓名/手机号" />
        </a-form-item>
        <a-form-item name="dateRange" label="发放日期">
          <a-range-picker v-model:value="formState.dateRange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <!-- 000546 住院 -->
      <div class="flex justify-end mb-2">
        <BaseExport
          type="物资"
          name="门诊物资发放查询"
          code="000553"
          :search-params="{
            stdate: formState['dateRange']?.[0],
            eddate: formState['dateRange']?.[1],
            pyjm: formState.pyjm,
            operationmode: 4,
            xmlbs: [30]
          }"
          >导出</BaseExport
        >
      </div>
      <BaseTable :loading="loading" column-code="000553" fill :data-source="tableData" bordered :pagination="pagination">
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'mc'">
            <MedicineInfo :value="{ mc: record?.mc, gg: record?.gg, cj: record?.cj }" />
          </template>
          <template v-if="column.dataIndex === 'yfsl'">
            <div>{{ record?.yfsl }}({{ record?.dw }})</div>
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import dayjs from 'dayjs'
import SearchContainer from '@/components/SearchContainer'

const formRef = ref(null)
const formState = ref({
  dateRange: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
})

const { loading, pagination, tableData, getData } = useTable({
  url: '/materials/comprehenive/getMtrFyRolloverSummaryDetails',
  params: formState.value,
  immediate: true,
  formatParams: (params) => {
    return {
      stdate: params['dateRange']?.[0],
      eddate: params['dateRange']?.[1],
      pyjm: params.pyjm,
      operationmode: 4,
      xmlbs: [30]
    }
  }
})
</script>
